/* Exception */
object test2 {
	def main():Unit = { 
	    try {
	      println((new ExceptionTest()).initMyVar(0));
	    } catch (e : MyException) {
	      println(e.getMessage() + " from main of type MyException");
	    } catch (e : MySpecialException) {
	      println(e.getMessage() + " from main of type MySpecialException");
	    }	
	}
}

class ExceptionTest {
	var myVar:Int;
	var myTab:Int[];
	var mySpecialException: MySpecialException;
    var myException: MyException;
    
	def initMyVar(myVar2:Int):Int throws ToolException = {
	    mySpecialException = new MySpecialException();
        myException = mySpecialException;
        
		try {
		  println("try " + myVar2);
		  //throw myException.setFromMethod("initMyVar");
		} catch(e: MySpecialException) {
		  println(e.getMessage() + " from " + e.getFromMethod() + " of type MySpecialException");
		  
		  throw e;
		} catch(e1: ToolException){
		  println(e1.getMessage() + " of type ToolException");
		  
		  throw e1;
		} finally {
		  myVar2 = 4;
		  println("Finally block " + myVar2);
		  throw myException;
		}

		return myVar2;
	}
}

class MyException extends ToolException {
    var fromMethod:String;
    
    def setFromMethod(from:String):MyException = {
       fromMethod = from;
       
       return this;
    }
    
    def getFromMethod():String = {
       return fromMethod;
    }
}

class MySpecialException extends MyException {
    def setFromMethod(from:String):MyException = {
       fromMethod = from + "(special)";
       msg = "salut";
       return this;
    }
}
